import heapq
class Solution(object):
    def getOrder(self, tasks):
        tasks = [[u, v, index] for index, (u, v) in enumerate(tasks)]
        tasks.sort()
        n = len(tasks)
        wait = []
        index = 0
        time = 1
        ans = []
        while wait or index < n:
            while index < n and tasks[index][0] <= time:
                heapq.heappush(wait, [tasks[index][1], tasks[index][2]])
                index += 1
            if wait:
                tast_time, task_index = heapq.heappop(wait)
                time += tast_time
                ans.append(task_index)
            else:
                time = tasks[index][0]
        return ans


